using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PharmacyDomain;
using ShivamEMR.Model.DataInterfaces.PharmacyDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.Pharmacy.Models;

namespace ShivamEMR.Web.Areas.Pharmacy.Controllers
{   
    public class DrugGroupController : Controller
    {
		private readonly IDrugGroupRepository druggroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DrugGroupController()
        {
            druggroupRepository = Registry.RepositoryFactory.GetDrugGroupRepository();
        }

        public DrugGroupController(IDrugGroupRepository druggroupRepository)
        {
			this.druggroupRepository = druggroupRepository;
        }

        //
        // GET: /DrugGroup/

        public ViewResult Index()
        {
           // return View(druggroupRepository.AllIncluding(druggroup => druggroup.Parent, druggroup => druggroup.Children, druggroup => druggroup.DrugGenerics));
            return View(druggroupRepository.All);
        }

        //
        // GET: /DrugGroup/Details/5

        public ViewResult Details(int id)
        {
            return View(druggroupRepository.Find(id));
        }

        //
        // GET: /DrugGroup/Create

        public ActionResult Create()
        {
			ViewBag.PossibleParents = druggroupRepository.All;
            return View();
        } 

        //
        // POST: /DrugGroup/Create

        [HttpPost]
        public ActionResult Create(DrugGroup druggroup)
        {
            if (ModelState.IsValid) {
                druggroupRepository.InsertOrUpdate(druggroup);
                druggroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = druggroupRepository.All;
				return View();
			}
        }
        
        //
        // GET: /DrugGroup/Edit/5
 
        public ActionResult Edit(int id)
        {
			ViewBag.PossibleParents = druggroupRepository.All;
             return View(druggroupRepository.Find(id));
        }

        //
        // POST: /DrugGroup/Edit/5

        [HttpPost]
        public ActionResult Edit(DrugGroup druggroup)
        {
            if (ModelState.IsValid) {
                druggroupRepository.InsertOrUpdate(druggroup);
                druggroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = druggroupRepository.All;
				return View();
			}
        }

        //
        // GET: /DrugGroup/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(druggroupRepository.Find(id));
        }

        //
        // POST: /DrugGroup/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var dg = druggroupRepository.Find(id);
            druggroupRepository.Delete(dg);
            druggroupRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

